package es.uned.hoomgle.hibernate.beans.impl;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.IndexedEmbedded;

import es.uned.hoomgle.hibernate.beans.interfaces.CityI;
import es.uned.hoomgle.hibernate.beans.interfaces.StateI;

@Entity
public class City implements CityI {
	/**
	 * @uml.property  name="id"
	 */
	@Id
	@Column
	@GeneratedValue
	private Integer id;
	/**
	 * @uml.property  name="name"
	 */
	@Column
	@Field
	private String name;
	
	@ManyToOne(cascade=CascadeType.ALL)
	@IndexedEmbedded
	private State state;

	@Override
	public Integer getId() {
		return id;
	}

	@Override
	public void setId(Integer id) {
		this.id = id;
		
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String getName() {
		return name;
	}

	public State getState() {
		return state;
	}

	public void setState(StateI state) {
		if(state instanceof State)
			this.state = (State)state;
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("City [Id=");
		builder.append(getId());
		builder.append(", name=");
		builder.append(getName());
		builder.append(", state=");
		builder.append(getState());
		builder.append("]");
		return builder.toString();
	}
}
